<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { NavBar, Tabbar, TabbarItem, Icon } from 'vant'

const router = useRouter()
const active = ref(0)

const navItems = [
  { name: '产品', path: '/', icon: 'shop-o' },
  { name: '订单', path: '/orders', icon: 'orders-o' },
  { name: '发货', path: '/shipments', icon: 'logistics' },
  { name: '送货单', path: '/delivery', icon: 'printer-o' }
]

function onTabChange(index: number) {
  active.value = index
  router.push(navItems[index].path)
}

// 根据当前路由设置active
const currentPath = router.currentRoute.value.path
navItems.forEach((item, index) => {
  if (item.path === currentPath || (currentPath.startsWith(item.path) && item.path !== '/')) {
    active.value = index
  }
})
</script>

<template>
  <div class="app">
    <NavBar title="ERP 管理系统" class="top-nav" />
    
    <main class="main-content">
      <router-view />
    </main>
    
    <Tabbar v-model="active" @change="onTabChange" class="bottom-nav">
      <TabbarItem v-for="(item, index) in navItems" :key="index" :icon="item.icon">
        {{ item.name }}
      </TabbarItem>
    </Tabbar>
  </div>
</template>

<style>
body { 
  margin: 0; 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.top-nav .van-nav-bar__title {
  color: white;
  font-weight: 600;
  font-size: 18px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.main-content {
  flex: 1;
  padding: 70px 16px 70px 16px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  border-top: 1px solid rgba(0,0,0,0.05);
}

.bottom-nav .van-tabbar-item {
  color: #666;
  transition: all 0.3s ease;
}

.bottom-nav .van-tabbar-item--active {
  color: #667eea;
  transform: translateY(-2px);
}

.bottom-nav .van-tabbar-item__icon {
  font-size: 20px;
  margin-bottom: 4px;
}

.bottom-nav .van-tabbar-item__text {
  font-size: 12px;
  font-weight: 500;
}

/* 全局样式调整 */
table { 
  border-collapse: collapse; 
  width: 100%; 
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

th, td { 
  border: 1px solid #e9ecef; 
  padding: 12px 8px; 
  text-align: center;
}

th { 
  background: linear-gradient(45deg, #667eea, #764ba2);
  color: white;
  font-weight: 600;
  font-size: 14px;
}

td {
  background: white;
  color: #333;
  font-size: 14px;
}

tr:nth-child(even) td {
  background: #f8f9fa;
}

tr:hover td {
  background: #e9ecef;
  transition: background-color 0.2s ease;
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* 页面切换动画 */
.main-content {
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .main-content {
    padding: 70px 12px 70px 12px;
  }
  
  .top-nav .van-nav-bar__title {
    font-size: 16px;
  }
  
  .bottom-nav .van-tabbar-item__icon {
    font-size: 18px;
  }
  
  .bottom-nav .van-tabbar-item__text {
    font-size: 11px;
  }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  }
  
  .top-nav {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  }
  
  .bottom-nav {
    background: rgba(44, 62, 80, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .bottom-nav .van-tabbar-item {
    color: #bdc3c7;
  }
  
  .bottom-nav .van-tabbar-item--active {
    color: #3498db;
  }
}
</style>
